package com.iteaj.network.server;

import com.iteaj.network.config.DeviceProperties;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.ChannelPipeline;

public abstract class AbstractUdpServer implements IotDeviceServer {

    private DeviceProperties config;

    public AbstractUdpServer(int port) {
        this.config = new DeviceProperties(port);
    }

    public AbstractUdpServer(DeviceProperties config) {
        this.config = config;
    }

    @Override
    public int port() {
        return this.config.getPort();
    }

    @Override
    public DeviceProperties config() {
        return this.config;
    }

    @Override
    public void initChannelPipeline(ChannelPipeline pipeline) {
        pipeline.addFirst(getMessageDecoder());
    }

    /**
     * 返回设备解码器
     * @return
     */
    public abstract ChannelInboundHandlerAdapter getMessageDecoder();
}
